package com.ifast.asset.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.ifast.asset.dao.IpsegmentDao;
import com.ifast.asset.domain.IpsegmentDO;
import com.ifast.asset.service.IpsegmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ifast.common.base.CoreServiceImpl;


/**
 * 
 * <pre>
 * 
 * </pre>
 * <small> 2021-03-15 10:45:44 | Aron</small>
 */
@Service
public class IpsegmentServiceImpl extends CoreServiceImpl<IpsegmentDao, IpsegmentDO> implements IpsegmentService {

    @Autowired
    IpsegmentService ipsegmentService;
    @Override
    public void checkIpSegment(String ip) {

        String[] ipString = ip.split("\\.");
        ip = ipString[0] + "." + ipString[1] +"."+ ipString[2]+".0/24";
        //传递ip  以24为掩码检测  数据库中是否存在此ip段   如果不存在则添加
        Wrapper wrapper = new EntityWrapper<IpsegmentDO>();
        wrapper.eq("ip",ip);
        IpsegmentDO ipsegmentDO = ipsegmentService.selectOne(wrapper);
        if (ipsegmentDO==null){

            //证明此时并无此  网段
            IpsegmentDO ipsegment = new IpsegmentDO();
            ipsegment.setIp(ip);
            ipsegmentService.insert(ipsegment);
        }
    }

    public static void main(String[] args) {
        String ip = "192.168.2.1";
        String[] ipString = ip.split("\\.");
        System.out.println(ipString.length);
    }
}
